﻿using DotNetty.Codecs.Json;
using DotNetty.Handlers.Logging;
using DotNetty.Handlers.Timeout;
using DotNetty.Transport.Channels;
using DotNetty.Transport.Channels.Sockets;
using System;
using System.Collections.Generic;
using System.Text;
using TestNetty.Service.Handlers;
using TestNetty.Service.Model;


namespace TestNetty.Service.Initializers
{
    public class TcpServerInitializer : ChannelInitializer<ISocketChannel>
    {
        protected override void InitChannel(ISocketChannel channel)
        {
            IChannelPipeline pipeline = channel.Pipeline;
            pipeline.AddLast(new LoggingHandler("SRV-CONN"));
            pipeline.AddLast(new IdleStateHandler(30,30,60 * 5));//心跳超时
            pipeline.AddLast(new JsonEncoder());//编码器
            pipeline.AddLast(new JsonDecoder());//解码器
            pipeline.AddLast(new ReceptionHandler());//消息处理
            pipeline.AddLast(new HeartBeatHandler());//心跳
        }
    }
}
